<script type="text/javascript">
	var ws, name;


// 连接服务端
	function connect(port, path){
	    let url;
	    if(path==null){
	        url = "ws://" + document.domain + ":"+port;
	    }else{
	        url = "wss://" + document.domain + "/"+path;
	    }
		// 创建websocket
// 		ws = new WebSocket("ws://" + document.domain + ":"+port);
		ws = new WebSocket(url);
		// 当socket连接打开时，发送登录信息
		ws.onopen = function(){
			var name = "{$userinfo.nickname}";
			// 登录
			var userid = "{$userinfo.id}";
			var login_data = '{"type":"login","client_name":"' + name.replace(/"/g, '\\"') + '","client_id":"'+userid+'"}';
			console.log("websocket握手成功，发送登录数据:" + login_data);
			ws.send(login_data);
		// 当有消息时根据消息类型显示不同信息
		ws.onmessage = onmessage;
		ws.onclose = function(){
			console.log("连接关闭，定时重连");
			connect();
		};
		ws.onerror = function() {
			console.log("出现错误");
		};
	}
	}

	var inte = parseInt(Math.random()*12+1);
	function onmessage(e) {
		
	
		
		
		var rate = 0;
		var robot_rate = {:C('robot_rate')} ? {:C('robot_rate')} : 3;
		switch({:C('robot_rate')}){
			case 5:
				rate = 5;
				break;
			case 4:
				rate = 10;
				break;
			case 3:
				rate = 25;
				break;
			case 2:
				rate = 35;
				break;
			case 1:
				rate = 45;
				break;
			default:
				rate = 25;
				break;
		}
		// console.log(e.data);
		var data = eval("(" + e.data + ")");
			// console.log(data)
		switch(data['type']) {
			// 服务端ping客户端
			case 'ping':
				$('#xs').html(data.content+{:C('online')});
				ws.send('{"type":"pong"}');
				inte--;
        console.log(inte);
				if(inte==0){
					ws.send('{"type":"robot"}');
                    inte = parseInt(Math.random()*rate+1);
					//inte = parseInt(Math.random()*rate+1)+2;
				}
				break;
				// 登录 更新用户列表
			case 'login':
				console.log(data['client_name'] + "登录成功");
				break;
				// 发言
			case 'say':
				// console.log(data['client_name'] + "发言");
				say(data['uid'],data['from_client_name'], data['head_img_url'], data['content'], data['time']);
				break;
				// 用户退出 更新用户列表
			case 'logout':
				break;
			case 'broadcast':
				//alert('client');
			
				//房管
			case 'admin':
				if(data['content']=='BTC，给您带来不一样的数字货币新体验！'){
					break;
				}
				//$("#03").prepend('<li class="notice"><center>' + data["content"] + '</center></li>');
				//$("#03").prepend('<p class="bettime">'+data["time"]+'</p>');
				
				console.log("准备翻译:'" + data["content"] + "'");
				var htm = $.i18n.trans(data["content"]);
				console.log("翻译后：", htm);
				document.getElementById("alert1").innerHTML=htm;
				// document.getElementById("alert1").innerHTML=data["content"];
				
				$(".alert1").show();
				setTimeout( "$('.alert1').fadeOut()" , 2000);
				break;
				//系统
			case 'system':
				if(data["content"].indexOf("结算已完毕") != -1){
					location.reload();
				}
				//$("#03").prepend('<li class="notice"><center>' + data["content"] + '</center></li>');
				//$("#03").prepend('<p class="bettime">'+data["time"]+'</p>');
				break;
				//积分减
			case 'points':
				$('#sy').html((parseFloat($('#sy').html())-data['content']).toFixed(1));
				break;
				//积分加
			case 'pointsadd':
				$('#sy').html((parseFloat($('#sy').html())+data['points']).toFixed(1));
				//parent.layer.msg('恭喜竞猜成功');
				break;
				//重载
			case 'reload':
				if('{$userinfo.id}'==9){
					window.location.href=window.location.href;
				}
				break;
				//切换
			case 'switch':
				parent.location.reload();
				break;	
		}
	}

	// 提交对话
	function onSubmit(input) {
		
		if(parseInt($('#money').text()) <=0){
			layer.alert("余额不足"); return false;
		}

		var headimgurl = '{$userinfo.headimgurl}';
		var from_client_name = '{$userinfo.nickname}';
		
		if(input==''){
			//$('#textarea').focus();
			return false;
		}
		
		  
		
		ws.send('{"type":"say","client_name":"'+from_client_name+'","headimgurl":"'+headimgurl+'","content":"' + input.replace(/"/g, '\\"').replace(/\n/g, '\\n').replace(/\r/g, '\\r') + '"}');
		// var num = input.replace(/[^0-9]/ig,"");
		var num = input.replace(/^.*?(\d+)$/, '$1');
		console.log(num);
				var money = $("#money").text()-num;
				$("#money").text(money.toFixed(2));
		 
		
		//$('#textarea').val('');
		//$('#dialog').scrollTop(0);
	}

	// 发言
	function say(uid, from_client_name, head_img_url, content, time) {
		
		if(content.indexOf("点") > -1){
			var dianq = content.split("点");
			var lang = $('#run-lun').html();
			if(lang == "Round"){
				var wenzi = dianq[0] + $.i18n.trans("jnd281-点", "spot");
			}
			if(lang == "輪數"){
				var wenzi = dianq[0] + $.i18n.trans("jnd281-点", "點");
			}
			if(lang == "轮数"){
				var wenzi = dianq[0] + $.i18n.trans("jnd281-点", "点");
			}
			//ssss
			if(lang == "Số vòng"){
				var wenzi = dianq[0] + $.i18n.trans("jnd281-点", "Điểm");
			}
			if(lang == "Pusingan"){
				var wenzi = dianq[0] + $.i18n.trans("jnd281-点", "Titik");
			}			
		} else {
			var wenzi = content.replace(/\d/g, "");
			var lang = $('#run-lun').html();
			if(lang == "Round"){
				if(wenzi == "大"){
					wenzi = $.i18n.trans('jnd281-'+wenzi, "Long");
				}
				if(wenzi == "小"){
					wenzi = $.i18n.trans('jnd281-'+wenzi, "Short");
				}
				if(wenzi == "单"){
					wenzi = $.i18n.trans('jnd281-'+wenzi, "Single");
				}
				if(wenzi == "双"){
					wenzi = $.i18n.trans('jnd281-'+wenzi, "Double");
				}
				if(wenzi == "极大"){
					wenzi = $.i18n.trans('jnd281-'+wenzi, "Very long");
				}
				if(wenzi == "大单"){
					wenzi = $.i18n.trans('jnd281-'+wenzi, "Gaudo");
				}
				if(wenzi == "小单"){
					wenzi = $.i18n.trans('jnd281-'+wenzi, "Much shorter");
				}
				if(wenzi == "大双"){
					wenzi = $.i18n.trans('jnd281-'+wenzi, "Long altitude");
				}
				if(wenzi == "小双"){
					wenzi = $.i18n.trans('jnd281-'+wenzi, "Short altitude");
				}
				if(wenzi == "极小"){
					wenzi = $.i18n.trans('jnd281-'+wenzi, "Very low");
				}
				
			}
			
			if(lang == "輪數"){
				if(wenzi == "大"){
					wenzi = $.i18n.trans('jnd281-'+wenzi, "高");
				}
				if(wenzi == "小"){
					wenzi = $.i18n.trans('jnd281-'+wenzi, "低");
				}
				if(wenzi == "单"){
					wenzi = $.i18n.trans('jnd281-'+wenzi, "多");
				}
				if(wenzi == "双"){
					wenzi = $.i18n.trans('jnd281-'+wenzi, "空");
				}
				if(wenzi == "极大"){
					wenzi = $.i18n.trans('jnd281-'+wenzi, "極高");
				}
				if(wenzi == "大单"){
					wenzi = $.i18n.trans('jnd281-'+wenzi, "高多");
				}
				if(wenzi == "小单"){
					wenzi = $.i18n.trans('jnd281-'+wenzi, "低多");
				}
				if(wenzi == "大双"){
					wenzi = $.i18n.trans('jnd281-'+wenzi, "高空");
				}
				if(wenzi == "小双"){
					wenzi = $.i18n.trans('jnd281-'+wenzi, "低空");
				}
				if(wenzi == "极小"){
					wenzi = $.i18n.trans('jnd281-'+wenzi, "極低");
				}
				
			}
			if(lang == "轮数"){
				if(wenzi == "大"){
					wenzi = $.i18n.trans('jnd281-'+wenzi, "高");
				}
				if(wenzi == "小"){
					wenzi = $.i18n.trans('jnd281-'+wenzi, "低");
				}
				if(wenzi == "单"){
					wenzi = $.i18n.trans('jnd281-'+wenzi, "多");
				}
				if(wenzi == "双"){
					wenzi = $.i18n.trans('jnd281-'+wenzi, "空");
				}
				if(wenzi == "极大"){
					wenzi = $.i18n.trans('jnd281-'+wenzi, "极高");
				}
				if(wenzi == "大单"){
					wenzi = $.i18n.trans('jnd281-'+wenzi, "高多");
				}
				if(wenzi == "小单"){
					wenzi = $.i18n.trans('jnd281-'+wenzi, "低多");
				}
				if(wenzi == "大双"){
					wenzi = $.i18n.trans('jnd281-'+wenzi, "高空");
				}
				if(wenzi == "小双"){
					wenzi = $.i18n.trans('jnd281-'+wenzi, "低空");
				}
				if(wenzi == "极小"){
					wenzi = $.i18n.trans('jnd281-'+wenzi, "极低");
				}
				
			}
			
			if(lang == "Số vòng"){
				if(wenzi == "大"){
					wenzi = $.i18n.trans('jnd281-'+wenzi, "Cao");
				}
				if(wenzi == "小"){
					wenzi = $.i18n.trans('jnd281-'+wenzi, "Thấp");
				}
				if(wenzi == "单"){
					wenzi = $.i18n.trans('jnd281-'+wenzi, "Lẻ");
				}
				if(wenzi == "双"){
					wenzi = $.i18n.trans('jnd281-'+wenzi, "Chẵn");
				}
				if(wenzi == "极大"){
					wenzi = $.i18n.trans('jnd281-'+wenzi, "Cực lớn");
				}
				if(wenzi == "大单"){
					wenzi = $.i18n.trans('jnd281-'+wenzi, "Đơn lớn");
				}
				if(wenzi == "小单"){
					wenzi = $.i18n.trans('jnd281-'+wenzi, "Đơn nhỏ");
				}
				if(wenzi == "大双"){
					wenzi = $.i18n.trans('jnd281-'+wenzi, "Gấp đôi");
				}
				if(wenzi == "小双"){
					wenzi = $.i18n.trans('jnd281-'+wenzi, "Đôi nhỏ");
				}
				if(wenzi == "极小"){
					wenzi = $.i18n.trans('jnd281-'+wenzi, "Cực nhỏ");
				}
				
			}
			if(lang == "Pusingan"){
				if(wenzi == "大"){
					wenzi = $.i18n.trans('jnd281-'+wenzi, "Tinggi");
				}
				if(wenzi == "小"){
					wenzi = $.i18n.trans('jnd281-'+wenzi, "Rendah");
				}
				if(wenzi == "单"){
					wenzi = $.i18n.trans('jnd281-'+wenzi, "Banyak");
				}
				if(wenzi == "双"){
					wenzi = $.i18n.trans('jnd281-'+wenzi, "Kosong");
				}
				if(wenzi == "极大"){
					wenzi = $.i18n.trans('jnd281-'+wenzi, "Sangat Tinggi");
				}
				if(wenzi == "大单"){
					wenzi = $.i18n.trans('jnd281-'+wenzi, "Tinggi dan Banyak");
				}
				if(wenzi == "小单"){
					wenzi = $.i18n.trans('jnd281-'+wenzi, "Rendah dan Banyak");
				}
				if(wenzi == "大双"){
					wenzi = $.i18n.trans('jnd281-'+wenzi, "Tinggi dan Kosong");
				}
				if(wenzi == "小双"){
					wenzi = $.i18n.trans('jnd281-'+wenzi, "Rendah dan Kosong");
				}
				if(wenzi == "极小"){
					wenzi = $.i18n.trans('jnd281-'+wenzi, "Sangat Rendah");
				}
				
			}
			
			wenzi = $.i18n.trans('jnd281-'+wenzi, wenzi);
		}
		
		if(content.indexOf("点") > -1){
					var dianh = content.split("点");
					var shuzi = dianh[1];
				} else {
					var shuzi = content.replace(/[^0-9]/ig, "");
				}
		var lunshu = $("#fjlunshu").html();
		var caozuoaction = $('#caozuoaction').text()
		if(caozuoaction=='跟单'){
			caozuoaction = '跟单' 
		}
		if(caozuoaction=='跟單'){
			caozuoaction = '跟單' 
		}
		if(caozuoaction=='BUY'){
			caozuoaction = 'BUY' 
		}
		
		

		
		if('{$userinfo.id}'==uid){
			$(".ws-gzxxt").prepend('<li class="chartBoxContentRow ws-gzxxli"><div><div class="betinfo"><p class="uname">' + from_client_name +'</p><p>' + lunshu + '</p><p class="ws-jypl">' + wenzi + '</p><p class="ws-dljy"  style="font-size:12px;">' + shuzi + '</p><p style="font-size:12px;"><span  class="ws-gdcz" onclick="do233(this)" data-zjyxx="' + content + '" >'+caozuoaction+'</span></p></div></div></li>');
		}else{
			$(".ws-gzxxt").prepend('<li class="chartBoxContentRow ws-gzxxli"><div><div class="betinfo"><p class="uname">' + from_client_name +'</p><p>' + lunshu + '</p><p class="ws-jypl">' + wenzi + '</p><p class="ws-dljy"  style="font-size:12px;">' + shuzi + '</p><p style="font-size:12px;"><span class="ws-gdcz" onclick="do233(this)" data-zjyxx="' + content + '" >'+caozuoaction+'</span></p></div></div></li>');
		}
		
	}
	function do233(obj){
		var zjyxx = $(obj).data("zjyxx");
		    	
		    	if(zjyxx.indexOf("点") > -1){
					var dianq2 = zjyxx.split("点");
					var lang = $('#run-lun').html();
					if(lang == "Round"){
						$('#gd-ddnr').html(dianq2[0] + "spot");
					}
					if(lang == "輪數"){
						$('#gd-ddnr').html(dianq2[0] + "點");
					}
					if(lang == "轮数"){
						$('#gd-ddnr').html(dianq2[0] + "点");
					}
					if(lang == "Số vòng"){
						$('#gd-ddnr').html(dianq2[0] + "Điểm");
					}
					if(lang == "Pusingan"){
						$('#gd-ddnr').html(dianq2[0] + "Titik");
					}
					
					$('#gd-ddnr').attr("data-wenzi", dianq2[0] + "点");
					
				} else {
					var jyplbox = zjyxx.replace(/\d/g, "");
					$('#gd-ddnr').html(jyplbox);
					
						var lang = $('#run-lun').html();
						if(lang == "轮数"){
						if(jyplbox == "大"){
							$('#gd-ddnr').html("高");
						}
						if(jyplbox == "小"){
							$('#gd-ddnr').html("低");
						}
						if(jyplbox == "单"){
							$('#gd-ddnr').html("多");
						}
						if(jyplbox == "双"){
							$('#gd-ddnr').html("空");
						}
						if(jyplbox == "极大"){
							$('#gd-ddnr').html("极高");
						}
						if(jyplbox == "大单"){
							$('#gd-ddnr').html("高多");
						}
						if(jyplbox == "小单"){
							$('#gd-ddnr').html("低多");
						}
						if(jyplbox == "大双"){
							$('#gd-ddnr').html("高空");
						}
						if(jyplbox == "小双"){
							$('#gd-ddnr').html("低空");
						}
						if(jyplbox == "极小"){
							$('#gd-ddnr').html("极低");
						}
						
					}
					if(lang == "Round"){
						if(jyplbox == "大"){
							$('#gd-ddnr').html("Long");
						}
						if(jyplbox == "小"){
							$('#gd-ddnr').html("Short");
						}
						if(jyplbox == "单"){
							$('#gd-ddnr').html("Single");
						}
						if(jyplbox == "双"){
							$('#gd-ddnr').html("Double");
						}
						if(jyplbox == "极大"){
							$('#gd-ddnr').html("Very long");
						}
						if(jyplbox == "大单"){
							$('#gd-ddnr').html("Gaudo");
						}
						if(jyplbox == "小单"){
							$('#gd-ddnr').html("Much lower");
						}
						if(jyplbox == "大双"){
							$('#gd-ddnr').html("Long altitude");
						}
						if(jyplbox == "小双"){
							$('#gd-ddnr').html("Short altitude");
						}
						if(jyplbox == "极小"){
							$('#gd-ddnr').html("Very low");
						}
						
					}
					
					if(lang == "輪數"){
						if(jyplbox == "大"){
							$('#gd-ddnr').html("高");
						}
						if(jyplbox == "小"){
							$('#gd-ddnr').html("低");
						}
						if(jyplbox == "单"){
							$('#gd-ddnr').html("多");
						}
						if(jyplbox == "双"){
							$('#gd-ddnr').html("空");
						}
						if(jyplbox == "极大"){
							$('#gd-ddnr').html("極高");
						}
						if(jyplbox == "大单"){
							$('#gd-ddnr').html("高多");
						}
						if(jyplbox == "小单"){
							$('#gd-ddnr').html("低多");
						}
						if(jyplbox == "大双"){
							$('#gd-ddnr').html("高空");
						}
						if(jyplbox == "小双"){
							$('#gd-ddnr').html("低空");
						}
						if(jyplbox == "极小"){
							$('#gd-ddnr').html("極低");
						}
						
					}
					
					
					if(lang == "Số vòng"){
						if(jyplbox == "大"){
							$('#gd-ddnr').html("Cao");
						}
						if(jyplbox == "小"){
							$('#gd-ddnr').html("Thấp");
						}
						if(jyplbox == "单"){
							$('#gd-ddnr').html("Lẻ");
						}
						if(jyplbox == "双"){
							$('#gd-ddnr').html("Chẵn");
						}
						if(jyplbox == "极大"){
							$('#gd-ddnr').html("Cực lớn");
						}
						if(jyplbox == "大单"){
							$('#gd-ddnr').html("Đơn lớn");
						}
						if(jyplbox == "小单"){
							$('#gd-ddnr').html("Đơn nhỏ");
						}
						if(jyplbox == "大双"){
							$('#gd-ddnr').html("Gấp đôi");
						}
						if(jyplbox == "小双"){
							$('#gd-ddnr').html("Đôi nhỏ");
						}
						if(jyplbox == "极小"){
							$('#gd-ddnr').html("Cực nhỏ");
						}
						
					}
					
					if(lang == "Pusingan"){
						if(jyplbox == "大"){
							$('#gd-ddnr').html("Tinggi");
						}
						if(jyplbox == "小"){
							$('#gd-ddnr').html("Rendah");
						}
						if(jyplbox == "单"){
							$('#gd-ddnr').html("Banyak");
						}
						if(jyplbox == "双"){
							$('#gd-ddnr').html("Kosong");
						}
						if(jyplbox == "极大"){
							$('#gd-ddnr').html("Sangat Tinggi");
						}
						if(jyplbox == "大单"){
							$('#gd-ddnr').html("Tinggi dan Banyak");
						}
						if(jyplbox == "小单"){
							$('#gd-ddnr').html("Rendah dan Banyak");
						}
						if(jyplbox == "大双"){
							$('#gd-ddnr').html("Tinggi dan Kosong");
						}
						if(jyplbox == "小双"){
							$('#gd-ddnr').html("Rendah dan Kosong");
						}
						if(jyplbox == "极小"){
							$('#gd-ddnr').html("Sangat Rendah");
						}
						
					}
					
					$('#gd-ddnr').attr("data-wenzi", jyplbox);
					
				}
				
				
		    	if(zjyxx.indexOf("点") > -1){
					var dianq3 = zjyxx.split("点");
					$('.gd-zfsl').html(dianq3[1]);
				} else {
					var dljy = zjyxx.replace(/[^0-9]/ig, "");
					$('.gd-zfsl').html(dljy);
				}
		    	
		    	
				$('.gdtczz').show();
				$('#betBoxDom').show();
				
		
	}
</script>